package com.itheima.controller;

import com.itheima.entity.User;
import com.itheima.entity.UserDto;
import com.itheima.mapper.UserMapper;
import com.itheima.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping
    public User save(@RequestBody User user){
        return userService.insert(user);
    }

    @DeleteMapping
    public void deleteById(Long id){
        userService.deleteById(id);
    }

	@DeleteMapping("/delAll")
    public void deleteAll(){
        userService.deleteAll();
    }

    @GetMapping
    public User getById(Long id) {
        return userService.getById(id);
    }

    @PostMapping("/list")
    public List<User> getList(@RequestBody UserDto userDto){
        return userService.getList(userDto);
    }
}
